﻿using System;
using System.Collections.Generic;
using UILib;
using UnityEngine;
using XMainClient.UI;
using XMainClient.UI.UICommon;
using XUtliPoolLib;

namespace XMainClient
{
	// Token: 0x02000D0D RID: 3341
	internal class XSpriteIllustrationHandler : DlgHandlerBase
	{
		// Token: 0x170032DB RID: 13019
		// (get) Token: 0x0600BA91 RID: 47761 RVA: 0x00261EF8 File Offset: 0x002600F8
		protected override string FileName
		{
			get
			{
				return "GameSystem/SpriteSystem/SpriteIllustrationWindow";
			}
		}

		// Token: 0x0600BA92 RID: 47762 RVA: 0x00261F10 File Offset: 0x00260110
		protected override void Init()
		{
			this.m_TypeList.Clear();
			this.m_TypeTitle.Clear();
			this.m_LTypeName = (base.PanelObject.transform.Find("Bg/ScrollView/Table/L/TypeL/Name").GetComponent("XUILabel") as IXUILabel);
			this.m_STypeName = (base.PanelObject.transform.Find("Bg/ScrollView/Table/S/TypeL/Name").GetComponent("XUILabel") as IXUILabel);
			this.m_ATypeName = (base.PanelObject.transform.Find("Bg/ScrollView/Table/A/TypeL/Name").GetComponent("XUILabel") as IXUILabel);
			this.m_BTypeName = (base.PanelObject.transform.Find("Bg/ScrollView/Table/B/TypeL/Name").GetComponent("XUILabel") as IXUILabel);
			this.m_CTypeName = (base.PanelObject.transform.Find("Bg/ScrollView/Table/C/TypeL/Name").GetComponent("XUILabel") as IXUILabel);
			this.m_Close = (base.PanelObject.transform.Find("Bg/Close").GetComponent("XUIButton") as IXUIButton);
			for (int i = 1; i < XFastEnumIntEqualityComparer<SpriteQuality>.ToInt(SpriteQuality.MAX); i++)
			{
				SpriteQuality spriteQuality = (SpriteQuality)i;
				string s = spriteQuality.ToString();
				Transform item = base.PanelObject.transform.Find(XSingleton<XCommon>.singleton.StringCombine("Bg/ScrollView/Table/", s));
				this.m_TypeTitle.Add(item);
				IXUIList ixuilist = base.PanelObject.transform.Find(XSingleton<XCommon>.singleton.StringCombine("Bg/ScrollView/Table/", s, "/Grid")).GetComponent("XUIList") as IXUIList;
				ixuilist.RegisterRepositionHandle(new OnAfterRepostion(this.OnListRefreshFinished));
				this.m_TypeList.Add(ixuilist);
			}
			Transform transform = base.PanelObject.transform.Find("Bg/ScrollView/ItemTpl");
			this.m_SpritePool.SetupPool(transform.parent.gameObject, transform.gameObject, 10U, false);
			this.m_ScrollView = (base.PanelObject.transform.Find("Bg/ScrollView").GetComponent("XUIScrollView") as IXUIScrollView);
			this.m_Table = (base.PanelObject.transform.Find("Bg/ScrollView/Table").GetComponent("XUITable") as IXUITable);
			this.m_Title = (base.PanelObject.transform.Find("Bg/Tittle").GetComponent("XUILabel") as IXUILabel);
			this.m_Tip = (base.PanelObject.transform.Find("Tip").GetComponent("XUILabelSymbol") as IXUILabelSymbol);
		}

		// Token: 0x0600BA93 RID: 47763 RVA: 0x002621C6 File Offset: 0x002603C6
		private void OnListRefreshFinished()
		{
			this.m_Table.Reposition();
			this.m_ScrollView.ResetPosition();
		}

		// Token: 0x0600BA94 RID: 47764 RVA: 0x002621E1 File Offset: 0x002603E1
		public override void RegisterEvent()
		{
			this.m_Close.RegisterClickEventHandler(new ButtonClickEventHandler(this.OnCloseClicked));
		}

		// Token: 0x0600BA95 RID: 47765 RVA: 0x002621FC File Offset: 0x002603FC
		private void ClassifySpritesByQuality(List<uint> itemList, bool isItem)
		{
			uint item = 0;
			XSpriteSystemDocument specificDocument = XDocuments.GetSpecificDocument<XSpriteSystemDocument>(XSpriteSystemDocument.uuID);
			this.m_SpriteID.Clear();
			List<uint> list = new List<uint>();
			List<uint> list2 = new List<uint>();
			List<uint> list3 = new List<uint>();
			List<uint> list4 = new List<uint>();
			List<uint> list5 = new List<uint>();
			int i = 0;
			while (i < itemList.Count)
			{
				SpriteQuality spriteQuality;
				if (isItem)
				{
					SpritePreviewTable.RowData byItemID = specificDocument._SpritePreviewTable.GetByItemID(itemList[i]);
					bool flag = byItemID == null;
					if (!flag)
					{
						spriteQuality = (SpriteQuality)byItemID.ItemQuality;
						item = byItemID.ItemID;
						goto IL_B9;
					}
				}
				else
				{
					SpriteTable.RowData bySpriteID = specificDocument._SpriteTable.GetBySpriteID(itemList[i]);
					bool flag2 = bySpriteID == null;
					if (!flag2)
					{
						spriteQuality = (SpriteQuality)bySpriteID.SpriteQuality;
						item = bySpriteID.SpriteID;
						goto IL_B9;
					}
				}
				IL_116:
				i++;
				continue;
				IL_B9:
				switch (spriteQuality)
				{
				case SpriteQuality.C:
				{
					//uint item;
					list5.Add(item);
					break;
				}
				case SpriteQuality.B:
				{
					//uint item;
					list4.Add(item);
					break;
				}
				case SpriteQuality.A:
				{
					//uint item;
					list3.Add(item);
					break;
				}
				case SpriteQuality.S:
				{
					//uint item;
					list2.Add(item);
					break;
				}
				case SpriteQuality.L:
				{
					//uint item;
					list.Add(item);
					break;
				}
				}
				goto IL_116;
			}
			this.m_SpriteID.Add(list5);
			this.m_SpriteID.Add(list4);
			this.m_SpriteID.Add(list3);
			this.m_SpriteID.Add(list2);
			this.m_SpriteID.Add(list);
		}

		// Token: 0x0600BA96 RID: 47766 RVA: 0x0026237C File Offset: 0x0026057C
		private void ShowIllustration(List<uint> itemList, bool isItem, bool showTip)
		{
			this.m_Title.SetText(isItem ? XStringDefineProxy.GetString("SpriteAwardPreview") : XStringDefineProxy.GetString("SpriteIllustrationName"));
			this.SetIllustrationType(isItem ? XStringDefineProxy.GetString("SpriteIllustrationType1") : XStringDefineProxy.GetString("SpriteIllustrationType2"));
			XSpriteSystemDocument specificDocument = XDocuments.GetSpecificDocument<XSpriteSystemDocument>(XSpriteSystemDocument.uuID);
			this.m_Tip.InputText = XStringDefineProxy.GetString("SpriteLotterySafeTip", new object[]
			{
				specificDocument.SpecialSafeCount
			});
			this.m_Tip.SetVisible(showTip);
			this.m_ScrollView.ResetPosition();
			this.ClassifySpritesByQuality(itemList, isItem);
			this.m_SpritePool.FakeReturnAll();
			this.CreateIcon(SpriteQuality.L, isItem);
			this.CreateIcon(SpriteQuality.S, isItem);
			this.CreateIcon(SpriteQuality.A, isItem);
			this.CreateIcon(SpriteQuality.B, isItem);
			this.CreateIcon(SpriteQuality.C, isItem);
			this.m_SpritePool.ActualReturnAll(true);
		}

		// Token: 0x0600BA97 RID: 47767 RVA: 0x0026246C File Offset: 0x0026066C
		private void SetIllustrationType(string name)
		{
			this.m_LTypeName.SetText(name);
			this.m_STypeName.SetText(name);
			this.m_ATypeName.SetText(name);
			this.m_BTypeName.SetText(name);
			this.m_CTypeName.SetText(name);
		}

		// Token: 0x0600BA98 RID: 47768 RVA: 0x002624BC File Offset: 0x002606BC
		public void ShowSpriteEggIllustration(SpriteEggLotteryType type)
		{
			XSpriteSystemDocument specificDocument = XDocuments.GetSpecificDocument<XSpriteSystemDocument>(XSpriteSystemDocument.uuID);
			List<uint> list;
			bool flag = specificDocument._SpriteEggPreviewDict.TryGetValue(XFastEnumIntEqualityComparer<SpriteEggLotteryType>.ToInt(type), out list);
			if (flag)
			{
				bool flag2 = list.Count > 0;
				if (flag2)
				{
					this.ShowIllustration(list, true, type == SpriteEggLotteryType.Special);
				}
			}
		}

		// Token: 0x0600BA99 RID: 47769 RVA: 0x0026250C File Offset: 0x0026070C
		public void ShowSpriteAllIllustration()
		{
			XSpriteSystemDocument specificDocument = XDocuments.GetSpecificDocument<XSpriteSystemDocument>(XSpriteSystemDocument.uuID);
			bool flag = specificDocument.SpriteShowInIllustration.Count > 0;
			if (flag)
			{
				this.ShowIllustration(specificDocument.SpriteShowInIllustration, false, false);
			}
		}

		// Token: 0x0600BA9A RID: 47770 RVA: 0x00262548 File Offset: 0x00260748
		private void CreateIcon(SpriteQuality quality, bool isItem)
		{
			int index = XFastEnumIntEqualityComparer<SpriteQuality>.ToInt(quality) - 1;
			IXUIList ixuilist = this.m_TypeList[index];
			List<uint> list = this.m_SpriteID[index];
			this.m_TypeTitle[index].gameObject.SetActive(list.Count > 0);
			for (int i = 0; i < list.Count; i++)
			{
				GameObject gameObject = this.m_SpritePool.FetchGameObject(false);
				gameObject.transform.parent = ixuilist.gameObject.transform;
				if (isItem)
				{
					this.SetItemInfo(gameObject, list[i]);
				}
				else
				{
					this.SetSpriteInfo(gameObject, list[i]);
				}
				XSingleton<XGameUI>.singleton.m_uiTool.ChangePanel(gameObject, ixuilist.GetParentUIRect(), ixuilist.GetParentPanel());
			}
			ixuilist.Refresh();
		}

		// Token: 0x0600BA9B RID: 47771 RVA: 0x0026262C File Offset: 0x0026082C
		private void SetItemInfo(GameObject obj, uint itemID)
		{
			IXUISprite ixuisprite = obj.transform.Find("Icon").GetComponent("XUISprite") as IXUISprite;
			ixuisprite.ID = (ulong)itemID;
			XSingleton<XItemDrawerMgr>.singleton.normalItemDrawer.DrawItem(obj, (int)itemID, 0, false);
			ixuisprite.RegisterSpriteClickEventHandler(new SpriteClickEventHandler(XSingleton<UiUtility>.singleton.OnItemClick));
		}

		// Token: 0x0600BA9C RID: 47772 RVA: 0x00262690 File Offset: 0x00260890
		private void SetSpriteInfo(GameObject obj, uint spriteID)
		{
			XSingleton<XItemDrawerMgr>.singleton.normalItemDrawer.DrawItem(obj, (int)spriteID, 0, false);
			IXUISprite ixuisprite = obj.transform.Find("Icon").GetComponent("XUISprite") as IXUISprite;
			ixuisprite.ID = (ulong)spriteID;
			ixuisprite.RegisterSpriteClickEventHandler(new SpriteClickEventHandler(this.OnSpriteIconClicked));
		}

		// Token: 0x0600BA9D RID: 47773 RVA: 0x002626F0 File Offset: 0x002608F0
		private void OnSpriteIconClicked(IXUISprite spr)
		{
			uint spriteID = (uint)spr.ID;
			XSpriteSystemDocument specificDocument = XDocuments.GetSpecificDocument<XSpriteSystemDocument>(XSpriteSystemDocument.uuID);
			DlgBase<XSpriteDetailView, XSpriteDetailBehaviour>.singleton.ShowDetail(spriteID);
		}

		// Token: 0x0600BA9E RID: 47774 RVA: 0x00262720 File Offset: 0x00260920
		private bool OnCloseClicked(IXUIButton sp)
		{
			base.SetVisible(false);
			return true;
		}

		// Token: 0x04004AFD RID: 19197
		private IXUIButton m_Close;

		// Token: 0x04004AFE RID: 19198
		private XUIPool m_SpritePool = new XUIPool(XSingleton<XGameUI>.singleton.m_uiTool);

		// Token: 0x04004AFF RID: 19199
		private IXUIScrollView m_ScrollView;

		// Token: 0x04004B00 RID: 19200
		private IXUITable m_Table;

		// Token: 0x04004B01 RID: 19201
		private IXUILabel m_Title;

		// Token: 0x04004B02 RID: 19202
		private IXUILabelSymbol m_Tip;

		// Token: 0x04004B03 RID: 19203
		private IXUILabel m_LTypeName;

		// Token: 0x04004B04 RID: 19204
		private IXUILabel m_STypeName;

		// Token: 0x04004B05 RID: 19205
		private IXUILabel m_ATypeName;

		// Token: 0x04004B06 RID: 19206
		private IXUILabel m_BTypeName;

		// Token: 0x04004B07 RID: 19207
		private IXUILabel m_CTypeName;

		// Token: 0x04004B08 RID: 19208
		private List<IXUIList> m_TypeList = new List<IXUIList>();

		// Token: 0x04004B09 RID: 19209
		private List<List<uint>> m_SpriteID = new List<List<uint>>();

		// Token: 0x04004B0A RID: 19210
		private List<Transform> m_TypeTitle = new List<Transform>();
	}
}
